{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox-title">
        <h5>添加工单</h5>
    </div>
    <div class="ibox-content layui-form">
        <div class="layui-row layui-col-space10 layui-form-item ">
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <label class="layui-form-label">客户名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="server_name" lay-verify="required" placeholder="客户名称" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <label class="layui-form-label">工单名称：</label>
                <div class="layui-input-block">
                    <input type="text" name="work_name" lay-verify="required" placeholder="工单名称" class="layui-input ">
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <label class="layui-form-label">状态：</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="1" title="图片" lay-filter="type" checked>
                    <!--<input type="radio" name="status" value="2" title="表格" lay-filter="type">-->
                    <input type="radio" name="status" value="3" title="PDF" lay-filter="type">
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md10" id="imgs">
                <label class="layui-form-label">多图片上传</label>
                <div class="layui-input-block">
                    <input type="hidden" name="photo" id="photo" lay-verify="imgs">
                    <div id="uploader" class="containers">
                        <div class="queueList">
                            <div class="placeholder">
                                <div id="filePicker"></div>
                                <p>或将照片拖到这里</p>
                            </div>
                        </div>
                        <div class="statusBar" style="display:none;">
                            <div class="layui-progress layui-progress-big active" lay-showpercent="true">
                                <div class="layui-progress-bar layui-bg-blue" lay-percent="0%">
                                </div>
                                <span></span>
                            </div>
                            <div class="info"></div>
                            <div class="btns">
                                <div id="goPicker" class="filePicker2"></div>
                                <div class="uploadBtn">开始上传</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8 layui-hide"id="excel">
                <label class="layui-form-label">上传excel：</label>
                <input type="hidden" name="excel" id="lay-file" >
                <div class="layui-input-block">
                    <div id="lay-upload">上传excel</div>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        上传信息：
                        <div class="layui-upload-list" id="lay-list">
                        </div>
                    </blockquote>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8 layui-hide" id="pdf">
                <label class="layui-form-label">上传pdf：</label>
                <input type="hidden" name="pdf" id="lay-file1" >
                <div class="layui-input-block">
                    <div id="lay-upload1">上传pdf</div>
                    <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                        上传信息：
                        <div class="layui-upload-list" id="lay-list1">
                        </div>
                    </blockquote>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <label class="layui-form-label">用户：</label>
                <div class="layui-input-block">
                    <select name="user" lay-verify="required" xm-select="select1" xm-select-search="" xm-select-search-type="dl">
                        <option value="">请选择用户</option>
                        {if !empty($user)}
                        {foreach name="$user" item="vo"}
                        <option value="{$vo.m_id}">{$vo.m_name}</option>
                        {/foreach}
                        {/if}
                    </select>
                </div>
            </div>
            <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                    </button>
                    <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">返回</button>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var n = wk.uploads({num:3,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}"});
    function imgDel(e,obj){
        wk.uploads_del(e,obj,n,"{:url('Upload/deleteLocality')}");
    }
    layui.use(['form'], function() {
        var form = layui.form;
        form.on('radio(type)', function(data){
            if(data.value == 1){
                $('#imgs').removeClass('layui-hide');
                $('#excel,#pdf').addClass('layui-hide');
                $('#photo').attr('lay-verify','imgs');
                $('#lay-file,#lay-file1').removeAttr('lay-verify');
            }else if(data.value == 2){
                $('#excel').removeClass('layui-hide');
                $('#imgs,#pdf').addClass('layui-hide');
                wk.uploadFile({size:20,type:'xlsx,xls',url:"{:url('Upload/upload')}"});
                $('#lay-file').attr('lay-verify','imgs');
                $('#photo,#lay-file1').removeAttr('lay-verify');
            }else if(data.value == 3){
                $('#pdf').removeClass('layui-hide');
                $('#imgs,#excel').addClass('layui-hide');
                wk.uploadFile({size:20,num:1,type:'pdf',url:"{:url('Upload/upload')}"});
                $('#lay-file1').attr('lay-verify','imgs');
                $('#photo,#lay-file').removeAttr('lay-verify');
            }
        });
        form.verify({
            imgs: function(value, item){
                if(!value){
                    return '上传不能为空';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('orderAdd')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Order/workOrder')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });
</script>
</body>
</html>